<%-- 
    Document   : admin_accounts
    Created on : Jan 25, 2012, 1:28:41 PM
    Author     : Martin San Diego
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="ContentManagers.RoleManagers.AdminManager"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="ContentManagers.Security.Hasher"%>
<%@page import="ContentManagers.Security.Validator"%>
<%@page import="ContentManagers.RoleManagers.AuthenticationManager"%>
<%@page import="ContentManagers.Servlets.ServletAddPM"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="DBConnection.ConnectionFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% //employ temporary session management here
            try{
            boolean check = false;
        
            check = new AuthenticationManager().inSuchDB(2, request, response);
            
            if(check == false)
               new AuthenticationManager().redirectToProperIndex(2, request, response);
            
            else
             {
        %>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="css/admin_int.css" />
        <script type='text/javascript' src='Javascript/adminjs.js'></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>EXPIRED PASSWORDS</title>
    </head>
    <body>
        <%@ include file="admin_header.jsp"%>
        
        <div id ="body_wrapper">
            <div id="product_manager_options" class="content_box">
            
            
        <%
        out.println("Product Manager accounts with EXPIRED PASSWORDS<br><br>");
        
        ResultSet rs = new AdminManager().getLockedPMAccounts();
          
         //check if no valid row / move forward
          if(rs == null || rs.first() == false){
               out.println("No product manager accounts with expired passwords.<br><br>");
          }
          else {
            //restart from before first row
            rs.beforeFirst();
            
            int indexNo = 0;
            ArrayList indexer = new ArrayList();
            
            while(rs.next())
            {
               indexer.add(indexNo, rs.getString("product_manager_id"));
               %>
               <div class="renewPassword">
                <form name ="expiredPassword" method="post" onsubmit="" action="../ServletRenewPMPassword">
                  <table class="create"><tr><td>Username: </td><td><%
                    out.println(rs.getString("username"));
                  %>
                   </td></tr><input type="text" name="pmIndex" value="<%out.println(indexNo);%>" hidden/>        
                    <tr><td>New Password: </td>
                        <td><input type="password" name="password1" value</td></tr>
                    <tr><td>Retype-Password: </td> 
                        <Td><input type="password" name="password2" value=""/></td></tr>
                    <tr><td></td><td><input type="submit" name="submit" value="Renew Password"/><!--input type="submit" name="submit" value="Delete"/--></td></tr></table>
                 <%
                 if((session.getAttribute("errorMessage"))!=null)
                 {
                    int formNo = Integer.parseInt(session.getAttribute("formNo").toString());
                    if((session.getAttribute("errorMessage"))== "0" && formNo==indexNo)
                        out.println("Password fields cannot be empty.");
                    else if((session.getAttribute("errorMessage"))== "1" && formNo==indexNo)
                        out.println("Passwords do not match.");
                    else if((session.getAttribute("errorMessage"))== "2" && formNo==indexNo)
                        out.println("A database error has occured.");
                    
                 }
                 %>
                </form>
                </div>
                <br>
               <%
               
               indexNo++;
            }
            //make sure to clear error messages
            session.removeAttribute("errorMessage");
            
            //pass the array using session
            request.getSession().setAttribute("indexer", indexer);
          
          }
        
        
        %>
            </div>
            
            <div id="accouting_manager_options" class="content_box">
           
        
         <%
        out.println("Accounting Manager accounts with EXPIRED PASSWORDS<br><br>");
        
        ResultSet rs2 = new AdminManager().getLockedAMAccounts();
         
          //move forward to check if a result is fetched
          if(rs2 == null || rs2.first()==false){
               out.println("No accounting manager accounts with expired passwords.<br><br>");
          }
          else {
            //move back
            rs2.beforeFirst();
            int indexNo = 0;
            ArrayList indexer = new ArrayList();
            
            while(rs2.next())
            {
               indexer.add(indexNo, rs2.getString("accounting_manager_id"));
               %>
               <div class="renewPassword">
                <form name ="expiredPassword" method="post" onsubmit="" action="../ServletRenewAMPassword">
                    <table class="create"><tr><td>Username: </td><td><%
                    out.println(rs2.getString("username"));
                  %></td></tr>
                  <input type="text" name="amIndex" value="<%out.println(indexNo);%>" hidden/>        
                  <tr><td>New Password:</td>
                      <td><input type="password" name="password1" value=""/></td></tr>
                      <Tr><Td>Retype-Password:</td>
                          <td><input type="password" name="password2" value=""/></td></tr>
                      <tr><td></td><td><input type="submit" name="submit" value="Renew Password"/></td></tr></table>
                 <%
                 if((session.getAttribute("errorMessage2"))!=null)
                 {
                    int formNo = Integer.parseInt(session.getAttribute("formNo2").toString());
                    if((session.getAttribute("errorMessage2"))== "0" && formNo==indexNo)
                        out.println("Password fields cannot be empty.");
                    else if((session.getAttribute("errorMessage2"))== "1" && formNo==indexNo)
                        out.println("Passwords do not match.");
                    else if((session.getAttribute("errorMessage2"))== "2" && formNo==indexNo)
                        out.println("A database error has occured.");
                    
                 }
                 %>
                </form>
                </div>
                <br>
               <%
               
               indexNo++;
            }
            //make sure to clear error messages
            session.removeAttribute("errorMessage2");
            //pass the array using session
            request.getSession().setAttribute("indexer2", indexer);
          
          }
        %>
     
            </div>
        </div>
        
        <%@ include file="admin_footer.jsp" %>
       <% //Call default footer file %>
        
    </body>
</html>


<% }
    }catch(Exception e)
        {   session = request.getSession();
            session.setAttribute("username", "xxxxdefaultxxxx");
            session.setAttribute("sessionID", "xxxxdefaultxxxx");
        
            response.sendRedirect("admin_index.jsp");}
            
%>